package fragments;


import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.baseproject.BaseFragment;
import com.example.administrator.newxlmedical.R;

import beans.RegisterInfoBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import constants.Constants;
import constants.HandlerConstant;
import customhandler.MyHandler;
import singleton.SingletonClass;

/**
 * A simple {@link Fragment} subclass.
 */
public class RegisterSuccessFragment extends BaseFragment {

    @BindView(R.id.tv_register_success_sure)
    TextView tvSure;
    Unbinder unbinder;
    @BindView(R.id.tv_register_success_back)
    TextView tvRegisterSuccessBack;

    private MyHandler allHandler;
    private RegisterInfoBean bean;

    public RegisterSuccessFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_register_success, container, false);
        unbinder = ButterKnife.bind(this, view);
        bean = (RegisterInfoBean) getArguments().getSerializable(Constants.BASE_IRIS_REGISTER_FRAGMENT);
        if (bean.isPut() && bean.isOneFingerprintRegister()){
            tvRegisterSuccessBack.setVisibility(View.GONE);
        }
        if (bean.isPut()){
            setText("添加指纹");
        }else if (bean.isOneFingerprintRegister()){
            setText("添加虹膜");
        }
        return view;
    }

    public void setText(String content){
        tvRegisterSuccessBack.setText(content);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @Override
    protected void initView() {
        super.initView();
        allHandler = SingletonClass.getSingleton(MyHandler.class);
    }

    @OnClick({R.id.tv_register_success_sure,R.id.tv_register_success_back})
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.tv_register_success_back :
                String s = tvRegisterSuccessBack.getText().toString();
                if ("添加指纹".equals(s)){
                    Message message = allHandler.obtainMessage();
                    message.what = HandlerConstant.FINGERPRINT_REGISTER;
                    message.obj = bean;
                    allHandler.sendMessage(message);
                }else {
                    Message message = allHandler.obtainMessage();
                    message.what = HandlerConstant.IRIS_REGISTER;
                    message.obj = bean;
                    allHandler.sendMessage(message);
                }
                break;
            case R.id.tv_register_success_sure:
                allHandler.sendEmptyMessage(HandlerConstant.REGISTER_SUCCESS_FRAGMENT_SURE);
                break;
        }
    }
}
